package com.zhu.controller;

import com.zhu.pojo.Area;
import com.zhu.pojo.Result;
import com.zhu.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/area")
public class AreaController {
    @Autowired
    private AreaService areaService;

    @PostMapping("/areaadd")
    public void areaadd(@RequestBody Area area){
        areaService.areaadd(area);
    }

    @PostMapping("/arealist")
    public List<Area> areaList(){
        return areaService.areaList();
    }

    @PostMapping("/search")
    public Result search(@RequestBody Area area){
        List<Area> a = areaService.search(area.getName());
        System.out.println(a);
        if(a.size()==0) return Result.fail("没找到");
        return Result.ok();
    }

    @PostMapping("/update")
    public void update(@RequestBody List<Area> list){
        areaService.update(list);
    }

    @PostMapping("/delete")
    public void delete(@RequestBody Area area){
        areaService.delete(area);
    }
}
